package com.wang.myblog.config;

import com.wang.myblog.Interceptor.LoginInterceptor;
import com.wang.myblog.common.Constants;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class MvcConfig implements WebMvcConfigurer {

    @Autowired
    LoginInterceptor loginInterceptor;


    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/upload/**").addResourceLocations("file:" + Constants.FILE_UPLOAD_DIC);
        registry.addResourceHandler("/uploads/**").addResourceLocations("file:"+Constants.COMMON_IMAGE_DIC);
        registry.addResourceHandler("/goods-img/**").addResourceLocations("file:" + Constants.FILE_UPLOAD_DIC);
    }


//    @Override
//    public void addInterceptors(InterceptorRegistry registry) {
//        registry.addInterceptor(loginInterceptor)
//                .addPathPatterns("/**").excludePathPatterns("/login","/","/index","/dologin","/asserts/**","/**/*.css", "/**/*.js", "/**/*.png ", "/**/*.jpg"
//                ,"/**/*.jpeg","/**/*.gif", "/**/fonts/*", "/**/*.svg");
//    }
@Override
public void addInterceptors(InterceptorRegistry registry) {
    registry.addInterceptor(loginInterceptor)
            .addPathPatterns("/**").excludePathPatterns("/login","/","/index","/dologin","/adminkit/**","/background/**","/common/**"
             ,"/front/**","/login/**","/upload/**","/uploads/**","/article","/search","/addComment"
             );
}

}
